<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>LinkExchanger ADMIN AREA</title>
</head>
<?
error_reporting(0);
include_once '../global-includes.php';
include_once "menu.php";

echo "<body bgcolor=$bgcolor>";

if(isset($_FILES['ufile']['name']))
$a=$_FILES['ufile']['name'];
else{
echo "You need to select a file.  Please try again.";
exit;
}
   
if ($_POST[type]==links) 
{
$buff2=$buff-1;   
$file = file($_FILES['ufile']['tmp_name']);	
for ($i=0;$i<count($file);$i++) 
{   
$record = explode("|", $file[$i]);

$cat=BaseDbService::execute_select_query("select cid from categories WHERE category='".$record[4]."'");
$cid=$cat[0][cid];


	
//change format date
$date=import_datetime($record[11]);

//екранізація HTML-тексту
$record[5]=mysql_escape_string($record[5]);
$record[6]=mysql_escape_string($record[6]);	
				
	if ($buff>1)
			{ 
				$value1="('$record[1]','$record[2]','$record[3]','$record[4]','$cid','$record[5]','$record[6]','$record[7]','$record[8]','$record[9]','$record[10]','$date','$record[0]')";//
				
				if (!isset($value2))
				{	
					$value2=$value1;
					$buff--;
				}
				else 
				{
					$value2=$value2.",".$value1;
					$buff--;
				}
			}
	else {
			$value1="('$record[1]','$record[2]','$record[3]','$record[4]','$cid','$record[5]','$record[6]','$record[7]','$record[8]','$record[9]','$record[10]','$date','$record[0]')";
			$value2=$value2.",".$value1;	
			$tmp5="insert into base(nick,url,mail,category,cid,htmltext,htmlimage,urllink,check_result,check_next,ip,check_date,date_create)value". $value2;
			$result=BaseDbService::execute_select_query($tmp5);
			$buff=$buff2; 
			unset($value2);
			unset($tmp5);
		 }
}

$tmp5="insert into base(nick,url,mail,category,cid,htmltext,htmlimage,urllink,check_result,check_next,ip,check_date,date_create)value". $value2;
$result = BaseDbService::execute_select_query($tmp5);
}else{
$buff2=$buff-1;   
$file = file($_FILES['ufile']['tmp_name']);	
for ($i=0;$i<count($file);$i++) 
{   
	$record = explode("|", $file[$i]);

//change format date
$date=import_date($record[2]);			
	if ($buff>1)
			{ 
				$value1="('$record[1]','$date')";
				
				if (!isset($value2))
				{	
					$value2=$value1;
					$buff--;
				}
				else 
				{
					$value2=$value2.",".$value1;
					$buff--;
				}
			}
	else {
			$value1="('$record[1]','$date')";
			$value2=$value2.",".$value1;	
			$tmp5="insert into categories(category,date)value". $value2;
			BaseDbService::execute_select_query($tmp5);
			$buff=$buff2; 
			unset($value2);
			unset($tmp5);
		 }
}

$tmp5="insert into categories(category,date)value". $value2;
$result=BaseDbService::execute_select_query($tmp5);
}
?>
<center>
	<table cellpadding=3 width=500>
		<tr>
			<td  align=center>
				<font face="Verdana, Arial" size="4" color="green">
					<b>Файл <?php echo $a ?> успішно імпортований!</b>
				</font>
				<hr size=1>
			</td>
		</tr>
	</table>
</center>



</body>
</html>
